package com.cppba.service;

import com.cppba.dto.UserDto;
import com.cppba.mapper.UserMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserService {

    private final UserMapper userMapper;

    @Autowired
    public UserService(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    public UserDto getById(Long id) {
        return userMapper.getById(id);
    }

    public PageInfo<UserDto> page(String username, Integer pageNumber, Integer pageSize) {
        PageInfo<UserDto> pageInfo = PageHelper.startPage(pageNumber, pageSize).doSelectPageInfo(() -> {
            userMapper.page(username);
        });
        return pageInfo;
    }
}
